<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body,
        html {
            height: 3000px;
        }
        
        div {
            font-size: 54px;
            font-weight: bold;
            width: 400px;
            height: 600px;
        }
        
        ul {
            position: fixed;
            right: 50px;
            top: 400px;
            list-style: none;
        }
        
        li {
            cursor: pointer;
            width: 200px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <div>一楼</div>
    <div>二楼</div>
    <div>三楼</div>
    <div>四楼</div>
    <ul>
        <li>一楼</li>
        <li>二楼</li>
        <li>三楼</li>
        <li>四楼</li>
    </ul>
    <script>
        let divs = document.querySelectorAll('div')
        let lis = document.querySelectorAll('li')
        let timerID = null
        console.log(divs[2].offsetTop);
        window.addEventListener('scroll', function() {
            console.log(document.documentElement.scrollTop);
        })
        lis.forEach(function(li, index) {
            li.addEventListener('click', function() {
                timerID = setInterval(function() {
                    let currrent = document.documentElement.scrollTop
                    let target = divs[index].offsetTop
                    if (currrent < target) {
                        currrent += 60
                        document.documentElement.scrollTop = currrent
                        if (target - currrent <= 50) {
                            document.documentElement.scrollTop = divs[index].offsetTop
                            clearInterval(timerID)
                            timerID = null
                        }
                    }
                    if (currrent > target) {
                        currrent -= 60
                        document.documentElement.scrollTop = currrent
                        if (currrent - target <= 50) {
                            document.documentElement.scrollTop = divs[index].offsetTop
                            clearInterval(timerID)
                            timerID = null
                        }
                    }
                }, 50)
            })
        })
    </script>
</body>

</html>